<?php

namespace app\admin\controller;

use think\Request;

class City extends BaseController
{
    public function cityList(){
        if(!judgeRole(__METHOD__)){
            $this->redirect("admin/index/forbidden");
        }
        if(request()->isAjax()){
            $info = model("PyCity")->select();
            $count = count($info);
            return getJson($count, $info);
        }
        return view();
    }

    public function cityAdd(){
        if(request()->isAjax()){
            $data=Request::instance()->param();
            return $this->uniteResponse(model("PyCity")->add($data),"城市添加成功");
        }
        return view();
    }

    public function cityEdit(){
        $cty_id=input("get.cty_id");
        if(request()->isAjax()){
            $data=Request::instance()->param();
            $this->uniteResponse(model("PyCity")->edit($data,$cty_id),"城市信息编辑成功");
        }

        $cityInfo=model("PyCity")->find($cty_id);
        $this->assign("cityInfo",$cityInfo);
        return view();
    }
}
